/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fusiondata;

import java.io.File;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author Administrator
 */
public class MyFileFilter extends FileFilter {

    Vector extensionsToFilter = new Vector();
    String typeDescription;

    public MyFileFilter(String exts, String desp) {
        super();
        StringTokenizer st = new StringTokenizer(exts, ";");
        while (st.hasMoreElements()) {
            extensionsToFilter.add(st.nextElement());
        }
        typeDescription = desp;
    }

    @Override
    public boolean accept(File file) {
        if (file.isDirectory()) {
            return true;
        }
        String fileName = file.getName();
        int periodIndex = fileName.lastIndexOf(".");
        if (periodIndex > 0 && periodIndex < fileName.length() - 1) {
            String extension = fileName.substring(periodIndex + 1).toLowerCase();
            for (int i = 0; i < extensionsToFilter.size(); i++) {
                if (extension.equals(extensionsToFilter.elementAt(i))) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public String getDescription() {
        String s = "";
        for (int i = 0; i < extensionsToFilter.size(); i++) {
            s += "*." + extensionsToFilter.elementAt(i);
        }
        return typeDescription + ":   " + s;
    }
}
